<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String inviter = request.getParameter("inviter");
    request.setAttribute("inviter", inviter);
    String inviterType = request.getParameter("inviterType");
    request.setAttribute("inviterType", inviterType);
    String driverype = request.getParameter("type");
    request.setAttribute("driverype", driverype);
%>
<html>
<head>
    <%@include file="../common/base.jsp" %>
    <meta charset="utf-8">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <link rel="stylesheet" href="/admin/css/reset.css?v=1.4" type="text/css"/>
    <link rel="stylesheet" href="/admin/css/index.css?version=${version}" type="text/css"/>
    <link rel="stylesheet" href="/admin/js/toastr/toastr.css?version=${version}" type="text/css"/>
    <title>司机申请</title>
    <script>
        window.appid = "${appid}";
    </script>
</head>
<body>
<div class="logo-page">
    <p>提交新申请，或查看您的申请进度</p>
    <p><input name="phone" type="tel" placeholder="手机号" data-rule-maxlength="11" maxlength="11"/></p>
    <input type="hidden" name="appid" value="${appid}"/>
    <input type="hidden" name="agentUuid" value="${agentUuid}"/>
    <input type="hidden" name="companyUuid" value="${companyUuid}"/>
    <input type="hidden" name="type" value="${driverype}"/>
    <p class="code-area"><input name="code" type="tel" placeholder="验证码" /><a
            class="code-btn ui-border-left" href="javascript:void(0) ">获取验证码</a></p>
    <p><a class="ui-btn sure-btn" href="javascript:void(0)">确定</a></p>
    <p>客服电话</p>
    <p><a href="tel:${tel}">${tel}</a></p>
    <br>
    <br>
    <br>
    <br>
    <br>
</div>
<style>
    .mark {
        position: fixed;
        top: 0;
        right: 0;
        left: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, .5);
        display: none;
    }

    .err-msg {
        position: fixed;
        top: 10%;
        background-color: #fff;
        z-index: 2;
        max-width: 300px;
        left: 50%;
        margin-left: -150px;
        text-align: center;
        border-radius: 10px;
        display: none;
        font-family: PingFang-SC;
    }

    .er-title {
        font-size: 30px;
        color: #4f5a67;
        margin: 12px 0;
    }

    .err-text {
        font-size: 18px;
        text-align: center;
        color: #9ea7b1;
        padding: 0 20px;
        word-break: break-all;
    }

    .err-btns {
        display: table;
        width: 100%;
        font-size: 16px;
        border-top: 1px solid #ccc;
        text-align: center;
        margin-top: 15px;
    }

    .err-btns > div {
        display: table-cell;
        padding: 12px 0;
        width: 50%;
        color: #3e88f5;
    }

    .fc6b7886 {
        color: #6b7886;
    }

    #getEdit {
        color: #3e88f5;
    }
</style>
<div class="err-msg" id="err-msg">
    <div class="er-title">提示</div>
    <div class="err-text">您提交的申请还在审核中，审核可能需要3~5天，请耐心等待，感谢您的注册；</div>
    <div class="err-btns">
        <div class="fc6b7886 colsemsg" style="color:#4f5a67">我知道了</div>
        <div><a href="" id="getEdit">去修改</a></div>
    </div>
</div>
<div class="err-msg" id="err-msg1">
    <div class="er-title">提示</div>
    <div class="err-text">您提交的申请还在审核中，审核可能需要3~5天，请耐心等待，感谢您的注册；</div>
    <div class="err-btns">
        <div class="colsemsg">好的</div>
    </div>
</div>
<div class="mark"></div>
<script type="text/javascript" src="//cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script type="text/javascript" src="${base}/plugin/layer-v3.0.3/layer.js"></script>
<%--<script type="text/javascript" src="${base}/plugin/crypto-js/crypto-js.min.js"></script>--%>
<%--<script type="text/javascript" src="${base}/plugin/jsencrypt/jsencrypt.min.js"></script>--%>
<script type="text/javascript" src="${base}/activity/giftCollection/js/ajaxUtil.js?version=${version}"></script>
<script type="text/javascript" src="${base}/admin/js/toastr/toastr.js?version=${version}"></script>
<script type="text/javascript">
    $(function () {
        var isCheck = true;
        var isSubmit = true;
        var gift = jck.ajax;
        basePath = '${base}';
        $(".code-btn").on('click', function () {
            if ($(".code-btn").attr("disabled") == "disabled") {
                return;
            }
            var phoneNum = $('input[name="phone"]').val();
            var regPhone = /^1[3|4|5|6|7|8|9]\d{9}$/;
            if (phoneNum == null || phoneNum == '') {
                $.toastr.warning('手机号码不能为空');
                return false;
            } else if (!regPhone.test(phoneNum)) {
                $.toastr.error('请填写正确格式的手机号码');
                return false;
            } else {
                $(".code-btn").attr("disabled", true);
                $(".code-btn").html("<span id='countTime'>60</span>s");
                //倒计时控件
                var time = setInterval(function () {
                    if ($("#countTime").html() == 0) {
                        $(".code-btn").html("获取验证码");
                        $(".code-btn").attr("disabled", false);
                        $(".code-btn").removeClass("active");
                        clearInterval(time);
                    } else {
                        $("#countTime").html($("#countTime").html() - 1);
                    }
                }, 1000);

                //请求发送发送验证码
                gift.ajax_md5({
                    url: '${base}/api/v1/common/identifyCode/send',
                    params: {mobile: phoneNum},
                    successCallBack: function (data) {
                        $.toastr.success("发送成功！");
                    },
                    errorCallBack: function (data) {
                        isCheck = true;
                        $("#countTime").html(0)
                        $(".code-btn").attr("disabled", false);
                        $.toastr.error("发送失败");
                    }
                });
            }

        });
        var errMap = {
            1: function (text) {//
                showErrMsg1('您提交的申请还在审核中，审核可能需要3~5天，请耐心等待，感谢您的注册；')
            },
            3: function (text) {
                showErrMsg(text)
            },
            2: function (text) {
                showErrMsg1('您的申请已通过，可通过登录页面直接登录；', '前往登录', '审核通过')
            },
            4: function (text) {
                showErrMsg1('您已有归属的业务，暂未开通多业务服务', '前往登录', '已有归属业务')
            },
        }
        $(".sure-btn").on('click', function () {
            //  if(isSubmit) {
            //  isSubmit = false;
            var phoneNum = $('input[name="phone"]').val();
            var codeNum = $('input[name="code"]').val();
            var regPhone = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
            var codeNum = $('input[name="code"]').val();
            var regCode = /^\d{4}$/;
            if (phoneNum == null || phoneNum == '') {
                $.toastr.warning('手机号码不能为空');
                return false;
            } else if (!regPhone.test(phoneNum)) {
                $.toastr.error('请填写正确格式的手机号码');
                return false;
            } else if (codeNum == null || codeNum == '') {
                $.toastr.warning("请输入验证码");
                return false;
            } else if (!regCode.test(codeNum)) {
                $.toastr.error('请填写4位数的正确验证码');
                return false;
            } else {
                $(".sure-btn").attr("disabled", true);
                var p = {
                    mobile: phoneNum,
                    code: codeNum,
                    appid: $('input[name="appid"]').val(),
                    type:${type}
                }
                gift.ajax_md5({
                    url: "${base}/admin/driver/login",
                    params: p,
                    successCallBack: function (data) {
                        $(".sure-btn").attr("disabled", false);
                        var url = ''
                        if (1 ===${driverype}) {//出租车
                            url = "${base}/h5/taxiDriver/add?appid=" + $('input[name="appid"]').val() + "&agentUuid=" + $('input[name="agentUuid"]').val() + "&companyUuid=" + $('input[name="companyUuid"]').val() + "&mobile=" + phoneNum + '&inviter=${inviter}&inviterType=${inviterType}&type=${driverype}'
                        } else {
                            url = "${base}/h5/driver/add?appid=" + $('input[name="appid"]').val() + "&agentUuid=" + $('input[name="agentUuid"]').val() + "&companyUuid=" + $('input[name="companyUuid"]').val() + "&mobile=" + phoneNum + '&inviter=${inviter}&inviterType=${inviterType}&type=${driverype}'
                        }
                        location.href = url
                    },
                    errorCallBack: function (data) {
                        $(".sure-btn").attr("disabled", false);
                        if (data.errCode == 3) {
                            util.localStorage.set(data.data.uuid, data.data);
                            var url = ''
                            if (1 ===${driverype}) {//出租车
                                url = '${base}/h5/taxiDriver/add?appid=${appid}&agentUuid=${agentUuid}&companyUuid=${companyUuid}&mobile=' + phoneNum + '&uuid=' + (data.data.uuid || '')
                            } else {
                                url = '${base}/h5/driver/add?appid=${appid}&agentUuid=${agentUuid}&companyUuid=${companyUuid}&type=${type}&mobile=' + phoneNum + '&uuid=' + (data.data.uuid || '')
                            }
                            $('#getEdit').attr('href', url);
                        }
                        try {
                            errMap[data.errCode](data.msg);
                        } catch (e) {
                            $.toastr.error(data.msg);
                        }
                    }
                });
            }
        });

        function showErrMsg(text) {
            $('#err-msg').find('.err-text').html('您提交的申请因为' + text + '原因导致审核无法通过，请重新提交；');
            $('#err-msg').show()
            $('.mark').show()
        }

        function showErrMsg1(text, btns, title) {
            var errmsg = $('#err-msg1');
            errmsg.find('.er-title').html(title || '提示')
            $('#err-msg1').find('.err-text').html(text);
            $('#err-msg1').show()
            $('#err-msg1').find('.err-btns .colsemsg').html(btns || '好的');
            $('.mark').show()
        }

        function hideErrMsg() {
            $('#err-msg1').hide()
            $('#err-msg').hide()
            $('.mark').hide()
        }

        var isIOS = navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
        $('.colsemsg').on('click', function () {
            if ($(this).html() === '前往登录') {
                if (isIOS) {//IOS
                    try {
                        window.webkit.messageHandlers.fallback1.postMessage('');
                    } catch (e) {
                        window.location.href = window.driverApp.ios
                    }
                } else {//安卓
                    try {
                        fallback.fallback();
                    } catch (e) {
                        window.location.href = window.driverApp.android
                    }
                }
            } else {
                hideErrMsg();
            }
        })
    })
</script>
</body>
</html>
